<?php


namespace app\admin\controller;


use app\admin\service\SignService;
use app\admin\model\Sign as SignModel;
use app\admin\validate\LayuiPageValidate;
use app\admin\validate\SignFindValidate;
use think\facade\Request;

class Sign extends BaseController
{
    # 渲染所有页面
    public function allSign()
    {
        return $this->fetch('sign/allSign');
    }

    # 渲染单个sign页面
    public function updateSign($id)
    {
        $model = new SignModel();
        $info = $model->getSign($id);
        $this->assign('info', $info);
        return $this->fetch('sign/updateSign');
    }

    # 渲染根据name和sign获取到流量记录
    public function getSignPop()
    {
        return $this->fetch('sign/everySignPop');
    }

    # =渲染根据name和sign获取到注册记录
    public function getSignReg()
    {
        return $this->fetch('sign/everySignReg');
    }

    # 获取对应name的所有标识
    public function allSignApi($name, $page, $limit)
    {
        (new SignFindValidate()) ->goCheck();
        $service = new SignService();
        $result = $service->getDataSign($name, $page, $limit);
        return json($result);
    }

    # 获取对应name和sign的所有标识
    public function allSignDataApi($model_str, $name, $sign, $page, $limit)
    {
        (new SignFindValidate()) ->goCheck();
        $service = new SignService();
        $result = $service->getAllSignData($name, $sign, $model_str, $page, $limit);
        return json($result);
    }

    # 查询接口
    public function findSignApi()
    {
        (new SignFindValidate()) ->goCheck();
        $data = Request::get();
        $service = new SignService();
        $result = $service->find_data($data);
        return json($result);
    }

    # 更新sign
    public function signUpdateApi()
    {
        $post = Request::post('data');
        $model = new SignModel();
        $result = $model->updateSign($post);
        return json($result);

    }

    # 禁用选择的sign
    public function disableSign()
    {
        $ids = Request::post('ids');
        $arr_ids = json_decode($ids, true);
        $model = new SignModel();
        $model->disableSign($arr_ids);
        return json(['code' => 200]);
    }

    # 禁用选择的sign
    public function noDisableSign()
    {
        $ids = Request::post('ids');
        $arr_ids = json_decode($ids, true);
        $model = new SignModel();
        $model->noDisableSign($arr_ids);
        return json(['code' => 200]);
    }
}